
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>


typedef struct {
    uint8_t  TID;       // TID_MVB_PD_DATA
    uint8_t  fcode;     // port byte size 端口字节大小 0,1,2,3,4
    uint16_t pdPort;    // port number 端口号
} mvb_data_header;


typedef struct {
    mvb_data_header  header;
    uint8_t  pdData[32];
} mvb_data_full;


#define MVB_DATA_COUNT 1
#define MVB_PD_DATA_LEN 32


int main() {
    int sockfd;
    char buffer[] = "Hello UDP";
    struct sockaddr_in local_addr, dest_addr;

    // 创建套接字
    sockfd = socket(AF_INET, SOCK_DGRAM, 0);
    
    // 绑定到特定网卡
    memset(&local_addr, 0, sizeof(local_addr));
    local_addr.sin_family = AF_INET;
    local_addr.sin_addr.s_addr = inet_addr("192.168.0.76");
    local_addr.sin_port = 0; // 系统自动分配端口
    bind(sockfd, (struct sockaddr*)&local_addr, sizeof(local_addr));

    // 设置目标地址
    memset(&dest_addr, 0, sizeof(dest_addr));
    dest_addr.sin_family = AF_INET;
    dest_addr.sin_port = htons(8000);
    dest_addr.sin_addr.s_addr = inet_addr("192.168.0.200");



    

    for (size_t k = 0; k < strlen(buffer); ++k) {
        printf("%02X ", ((uint8_t*)buffer)[k]);
    }
    printf("\n");

    // 发送数据
    sendto(sockfd, buffer, strlen(buffer), 0,
           (struct sockaddr*)&dest_addr, sizeof(dest_addr));
    
    close(sockfd);
    return 0;
}
